//
//  UTString+STDate.swift
//  iPhoneUTests
//
//  Created by Toj on 11/10/23.
//

import XCTest

final class UTString_STDate: XCTestCase {
    
    override func setUpWithError() throws {
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }
    
    override func tearDownWithError() throws {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
    }
    
    func testExample() throws {
        print("-->UTests: start \n")
        
        testStringDateSTSeries()
        
        print("-->UTests: \n")
        
        testStringDateStringSTSeries()
        
        print("-->UTests: end \n")
    }
    
    func testPerformanceExample() throws {
        // This is an example of a performance test case.
        self.measure {
            // Put the code you want to measure the time of here.
        }
    }
}

// MARK: - ST Date
extension UTString_STDate {
    
    func testStringDateSTSeries() {
        // 参考: 2023-11-10 10:00:00
        
        let formatter = DateFormatter()
        let date = Date(timeIntervalSince1970: 1699581600)
        formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
        let dateString = formatter.string(from: date)
        print("-->UTests: st: 用例: current -> \(dateString)")
        
        // 跨年: yyyy-MM-dd [1年, ~)
        testStringDateSTSeries_yyyy_MM_dd()
        // 今年: MM-dd [1天, 今年)
        testStringDateSTSeries_MM_dd()
        // 今日: HH:mm(24小时制) [30分, 1天内)
        testStringDateSTSeries_HH_mm()
        // 今日: 刚刚 [0秒, 30分)
        testStringDateSTSeries_gg()
    }
    
    // MARK: - 跨年: yyyy-MM-dd [1年, ~)
    func testStringDateSTSeries_yyyy_MM_dd() {
        var series = ""
        // 参考: 2023-11-10 10:00:00
        print("-->UTests: st: 跨年: yyyy-MM-dd [1年, ~)")
        
        // MARK: - 相差 (1年, ~)
        // 跨年: 2020-12-03 12:23:41
        series = 1606969421.st_dateSeries
        print("-->UTests: st: 用例: 2020-12-03 12:23:41, 预计: 2020-12-03, 实际: \(series)")
        // 跨年: 2011-08-12 13:45:56
        series = 1313127956.st_dateSeries
        print("-->UTests: st: 用例: 2011-08-12 13:45:56, 预计: 2011-08-12, 实际: \(series)")
        // 跨年: 2021-08-13 23:44:53
        series = 1628869493.st_dateSeries
        print("-->UTests: st: 用例: 2021-08-13 23:44:53, 预计: 2021-08-13, 实际: \(series)")
        // 跨年: 2022-12-08 23:45:32
        series = 1670514332.st_dateSeries
        print("-->UTests: st: 用例: 2022-12-08 23:45:32, 预计: 2022-12-08, 实际: \(series)")
        
        // MARK: - 相差 1年 多1秒
        // 跨年: 2022-11-10 09:59:59
        series = 1668045599.st_dateSeries
        print("-->UTests: st: 用例: 2022-11-10 09:59:59, 预计: 2022-11-10, 实际: \(series)")
        
        // MARK: - 相差 1年
        // 跨年: 2022-11-10 10:00:00
        series = 1668045600.st_dateSeries
        print("-->UTests: st: 用例: 2022-11-10 10:00:00, 预计: 2022-11-10, 实际: \(series)")
        
        // MARK: - 相差 1年 少1秒
        // 跨年: 2022-11-10 10:00:01
        series = 1668045601.st_dateSeries
        print("-->UTests: st: 用例: 2022-11-10 10:00:01, 预计: 2022-11-10, 实际: \(series)")
        
        // MARK: - 去年末
        // 跨年: 2022-12-31 23:59:59
        series = 1672502399.st_dateSeries
        print("-->UTests: st: 用例: 2022-12-31 23:59:59, 预计: 2022-12-31, 实际: \(series)")
    }
    
    // MARK: - 今年: MM-dd [1天, 今年)
    func testStringDateSTSeries_MM_dd() {
        var series = ""
        // 参考: 2023-11-10 10:00:00
        print("-->UTests: st: 今年: MM-dd [1天, 今年)")
        
        // 今年初
        // 跨年: 2023-01-01 00:00:00
        series = 1672502400.st_dateSeries
        print("-->UTests: st: 用例: 2023-01-01 00:00:00, 预计: 01-01, 实际: \(series)")
        // 今年初 1秒
        // 跨年: 2023-01-01 00:00:01
        series = 1672502401.st_dateSeries
        print("-->UTests: st: 用例: 2023-01-01 00:00:01, 预计: 01-01, 实际: \(series)")
        
        
        // MARK: - 相差 (1天, 1年)
        // MARK: 今年: 2023-02-10 08:34:57
        series = 1675989297.st_dateSeries
        print("-->UTests: st: 用例: 2023-02-10 08:34:57, 预计: 02-10, 实际: \(series)")
        // MARK: 今年: 2023-08-04 11:32:11
        series = 1691119931.st_dateSeries
        print("-->UTests: st: 用例: 2023-08-04 11:32:11, 预计: 08-04, 实际: \(series)")
        
        // MARK: - 相差 1天 1秒
        // MARK: 今年: 2023-11-09 09:59:59
        series = 1699495199.st_dateSeries
        print("-->UTests: st: 用例: 2023-11-09 09:59:59, 预计: 11-09, 实际: \(series)")
        // MARK: - 相差 1天
        // MARK: 今年: 2023-11-09 10:00:00
        series = 1699495200.st_dateSeries
        print("-->UTests: st: 用例: 2023-11-09 10:00:00, 预计: 11-09, 实际: \(series)")
    }
    
    // MARK: - 今日 HH:mm(24小时制) [30分, 1天内)
    func testStringDateSTSeries_HH_mm() {
        var series = ""
        // 参考: 2023-11-10 10:00:00
        print("-->UTests: st: 今日 HH:mm(24小时制) [30分, 1天内)")
        
        // MARK: - 相差 1天 少1秒
        // MARK: 今日: 2023-11-09 10:00:01
        series = 1699495201.st_dateSeries
        print("-->UTests: st: 用例: 2023-11-09 10:00:01, 预计: 10:00, 实际: \(series)")
        
        // MARK: - 相差 (30分, 1天)
        // MARK: 今日: 2023-11-09 23:07:34
        series = 1699542454.st_dateSeries
        print("-->UTests: st: 用例: 2023-11-09 23:07:34, 预计: 23:07, 实际: \(series)")
        // MARK: 今日: 2023-11-09 16:14:08
        series = 1699517648.st_dateSeries
        print("-->UTests: st: 用例: 2023-11-09 16:14:08, 预计: 16:14, 实际: \(series)")
        // MARK: 今日: 2023-11-10 08:34:57
        series = 1699576497.st_dateSeries
        print("-->UTests: st: 用例: 2023-11-10 08:34:57, 预计: 08:34, 实际: \(series)")
        
        // MARK: - 相差 30分 1秒
        // MARK: 今日: 2023-11-10 09:29:59
        series = 1699579799.st_dateSeries
        print("-->UTests: st: 用例: 2023-11-10 09:29:59, 预计: 09:29, 实际: \(series)")
        // MARK: - 相差 30分
        // MARK: 今日: 2023-11-10 09:30:00
        series = 1699579800.st_dateSeries
        print("-->UTests: st: 用例: 2023-11-10 09:30:00, 预计: 09:30, 实际: \(series)")
    }
    
    // MARK: - 刚刚 [0秒, 30分)
    func testStringDateSTSeries_gg() {
        var series = ""
        // 参考: 2023-11-10 10:00:00
        print("-->UTests: st: 刚刚 [0秒, 30分)")
        
        // MARK: - 相差 29分 59秒
        // MARK: 刚刚: 2023-11-10 09:30:01
        series = 1699579801.st_dateSeries
        print("-->UTests: st: 用例: 2023-11-10 09:30:01, 预计: 刚刚, 实际: \(series)")
        
        // MARK: - 相差 (1秒, 30分)
        // MARK: 刚刚: 2023-11-10 09:30:35
        series = 1699579835.st_dateSeries
        print("-->UTests: st: 用例: 2023-11-10 09:30:35, 预计: 刚刚, 实际: \(series)")
        // MARK: 刚刚: 2023-11-10 09:40:08
        series = 1699580408.st_dateSeries
        print("-->UTests: st: 用例: 2023-11-10 09:40:08, 预计: 刚刚, 实际: \(series)")
        // MARK: 刚刚: 2023-11-10 09:50:46
        series = 1699581046.st_dateSeries
        print("-->UTests: st: 用例: 2023-11-10 09:50:46, 预计: 刚刚, 实际: \(series)")
        
        // MARK: - 相差 1秒
        // MARK: 刚刚: 2023-11-10 09:59:59
        series = 1699581599.st_dateSeries
        print("-->UTests: st: 用例: 2023-11-10 09:59:59, 预计: 刚刚, 实际: \(series)")
        // MARK: - 相差 0秒
        // MARK: 刚刚: 2023-11-10 10:00:00
        series = 1699581600.st_dateSeries
        print("-->UTests: st: 用例: 2023-11-10 10:00:00, 预计: 刚刚, 实际: \(series)")
    }
}

// MARK: - ST DateString
extension UTString_STDate {
    
    func testStringDateStringSTSeries() {
        // 参考: 2023-11-10 10:00:00
        let formatter = DateFormatter()
        let date = Date(timeIntervalSince1970: 1699581600)
        formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
        let dateString = formatter.string(from: date)
        print("-->UTests: st_string: 用例: current -> \(dateString)")
        
        // 跨年: yyyy-MM-dd [1年, ~)
        testStringDateStringSTSeries_yyyy_MM_dd()
        // 今年: MM-dd [1天, 今年)
        testStringDateStringSTSeries_MM_dd()
        // 今日: HH:mm(24小时制) [30分, 1天内)
        testStringDateStringSTSeries_HH_mm()
        // 今日: 刚刚 [0秒, 30分)
        testStringDateStringSTSeries_gg()
    }
    
    // MARK: - 跨年: yyyy-MM-dd [1年, ~)
    func testStringDateStringSTSeries_yyyy_MM_dd() {
        var series = ""
        // 参考: 2023-11-10 10:00:00
        print("-->UTests: st: 跨年: yyyy-MM-dd [1年, ~)")
        
        // MARK: - 相差 (1年, ~)
        // MARK: 跨年:
        // MARK: 跨年: 2020-12-03 12:23:41
        series = "2020-12-03 12:23:41".st_dateSeries
        print("-->UTests: st_string: 用例: 2020-12-03 12:23:41, 预计: 2020-12-03, 实际: \(series)")
        // MARK: 跨年: 2011-08-12 13:45:56
        series = "2011-08-12 13:45:56".st_dateSeries
        print("-->UTests: st_string: 用例: 2011-08-12 13:45:56, 预计: 2011-08-12, 实际: \(series)")
        // MARK: 跨年: 2021-08-13 23:44:53
        series = "2021-08-13 23:44:53".st_dateSeries
        print("-->UTests: st_string: 用例: 2021-08-13 23:44:53, 预计: 2021-08-13, 实际: \(series)")
        // 时间: 2022-12-08 23:45:32
        series = "2022-12-08 23:45:32".st_dateSeries
        print("-->UTests: st_string: 用例: 2022-12-08 23:45:32, 预计: 2022-12-08, 实际: \(series)")
        
        // MARK: - 相差 1年 多1秒
        // MARK: 跨年: 2022-11-10 09:59:59
        series = "2022-11-10 09:59:59".st_dateSeries
        print("-->UTests: st_string: 用例: 2022-11-10 09:59:59, 预计: 2022-11-10, 实际: \(series)")
        // MARK: - 相差 1年
        // MARK: 跨年: 2022-11-10 10:00:00
        series = "2022-11-10 10:00:00".st_dateSeries
        print("-->UTests: st_string: 用例: 2022-11-10 10:00:00, 预计: 2022-11-10, 实际: \(series)")
        // MARK: - 相差 1年 少1秒
        // MARK: 今年: 2022-11-10 10:00:01
        series = "2022-11-10 10:00:01".st_dateSeries
        print("-->UTests: st_string: 用例: 2022-11-10 10:00:01, 预计: 2022-11-10, 实际: \(series)")
        
        // MARK: - 去年末
        // 跨年: 2022-12-31 23:59:59
        series = "2022-12-31 23:59:59".st_dateSeries
        print("-->UTests: st_string: 用例: 2022-12-31 23:59:59, 预计: 2022-12-31, 实际: \(series)")
    }
    
    // MARK: - 今年: MM-dd [1天内, 今年)
    func testStringDateStringSTSeries_MM_dd() {
        var series = ""
        // 参考: 2023-11-10 10:00:00
        print("-->UTests: st: 今年: MM-dd [1天内, 今年)")
        
        // MARK: 今年初
        // 时间: 2023-01-01 00:00:00
        series = "2023-01-01 00:00:00".st_dateSeries
        print("-->UTests: st_string: 用例: 2023-01-01 00:00:00, 预计: 01-01, 实际: \(series)")
        // 今年初 1秒
        // 时间: 2023-01-01 00:00:01
        series = "2023-01-01 00:00:01".st_dateSeries
        print("-->UTests: st_string: 用例: 2023-01-01 00:00:01, 预计: 01-01, 实际: \(series)")
        
        
        // MARK: - 相差 (1天, 今年)区间内
        // 时间: 2023-02-10 08:34:57
        series = "2023-02-10 08:34:57".st_dateSeries
        print("-->UTests: st_string: 用例: 2023-02-10 08:34:57, 预计: 02-10, 实际: \(series)")
        // 时间: 2023-08-04 11:32:11
        series = "2023-08-04 11:32:11".st_dateSeries
        print("-->UTests: st_string: 用例: 2023-08-04 11:32:11, 预计: 08-04, 实际: \(series)")
        
        // MARK: - 相差 1天 1秒
        // 时间: 2023-11-09 09:59:59
        series = "2023-11-09 09:59:59".st_dateSeries
        print("-->UTests: st_string: 用例: 2023-11-09 09:59:59, 预计: 11-09, 实际: \(series)")
        // MARK: - 相差 1天
        // 时间: 2023-11-09 10:00:00
        series = "2023-11-09 10:00:00".st_dateSeries
        print("-->UTests: st_string: 用例: 2023-11-09 10:00:00, 预计: 11-09, 实际: \(series)")
    }
    
    // MARK: - 今日 HH:mm(24小时制) [30分, 1天内)
    func testStringDateStringSTSeries_HH_mm() {
        var series = ""
        // 参考: 2023-11-10 10:00:00
        print("-->UTests: st: 今日 HH:mm(24小时制) [30分, 1天内)")
        
        // MARK: - 相差 1天 少1秒
        // MARK: 今日: 2023-11-09 10:00:01
        series = "2023-11-09 10:00:01".st_dateSeries
        print("-->UTests: st_string: 用例: 2023-11-09 10:00:01, 预计: 10:00, 实际: \(series)")
        
        // MARK: - 相差 (30分, 1天)
        // MARK: 今日: 2023-11-09 23:07:34
        series = "2023-11-09 23:07:34".st_dateSeries
        print("-->UTests: st_string: 用例: 2023-11-09 23:07:34, 预计: 23:07, 实际: \(series)")
        // MARK: 今日: 2023-11-09 16:14:08
        series = "2023-11-09 16:14:08".st_dateSeries
        print("-->UTests: st_string: 用例: 2023-11-09 16:14:08, 预计: 16:14, 实际: \(series)")
        // MARK: 今日: 2023-11-10 08:34:57
        series = "2023-11-10 08:34:57".st_dateSeries
        print("-->UTests: st_string: 用例: 2023-11-10 08:34:57, 预计: 08:34, 实际: \(series)")
        
        // MARK: - 相差 30分 1秒
        // MARK: 今日: 2023-11-10 09:29:59
        series = "2023-11-10 09:29:59".st_dateSeries
        print("-->UTests: st_string: 用例: 2023-11-10 09:29:59, 预计: 09:29, 实际: \(series)")
        // MARK: - 相差 30分
        // MARK: 今日: 2023-11-10 09:30:00
        series = "2023-11-10 09:30:00".st_dateSeries
        print("-->UTests: st_string: 用例: 2023-11-10 09:30:00, 预计: 09:30, 实际: \(series)")
    }
    
    // MARK: - 刚刚 [0秒, 30分)
    func testStringDateStringSTSeries_gg() {
        var series = ""
        // 参考: 2023-11-10 10:00:00
        print("-->UTests: st: 刚刚 [0秒, 30分)")
        
        // MARK: - 相差 29分 59秒
        // MARK: 刚刚: 2023-11-10 09:30:01
        series = "2023-11-10 09:30:01".st_dateSeries
        print("-->UTests: st_string: 用例: 2023-11-10 09:30:01, 预计: 刚刚, 实际: \(series)")
        
        // MARK: - 相差 (1秒, 30分)
        // MARK: 刚刚: 2023-11-10 09:30:35
        series = "2023-11-10 09:30:35".st_dateSeries
        print("-->UTests: st_string: 用例: 2023-11-10 09:30:35, 预计: 刚刚, 实际: \(series)")
        // MARK: 刚刚: 2023-11-10 09:40:08
        series = "2023-11-10 09:40:08".st_dateSeries
        print("-->UTests: st_string: 用例: 2023-11-10 09:40:08, 预计: 刚刚, 实际: \(series)")
        // MARK: 刚刚: 2023-11-10 09:50:46
        series = "2023-11-10 09:50:46".st_dateSeries
        print("-->UTests: st_string: 用例: 2023-11-10 09:50:46, 预计: 刚刚, 实际: \(series)")
        
        // MARK: - 相差 1秒
        // MARK: 刚刚: 2023-11-10 09:59:59
        series = "2023-11-10 09:59:59".st_dateSeries
        print("-->UTests: st_string: 用例: 2023-11-10 09:59:59, 预计: 刚刚, 实际: \(series)")
        // MARK: - 相差 0秒
        // MARK: 刚刚: 2023-11-10 10:00:00
        series = "2023-11-10 10:00:00".st_dateSeries
        print("-->UTests: st_string: 用例: 2023-11-10 10:00:00, 预计: 刚刚, 实际: \(series)")
    }
}
